$(function(){
    
    $("#form_aluno").validate({
        onfocusout: function (element) {
            $(element).valid();
        },
        errorPlacement: function(error, element) 
        {
            element.attr('title', error.text());
            $(".error").tooltip({   
                position: {
                    my: "center bottom-10",
                    at: "right top",
                    using: function(position, feedback) {
                        $(this).css(position);
                        $("<div>").addClass("arrow").addClass(feedback.vertical).addClass(feedback.horizontal).appendTo(this);
                    }
                },
                tooltipClass: "ttError"
            }); 
        }
    });
    
    $(".chosen-select").chosen();
    
    $(document).on('click','.add_item',function(){ 
        var itemid = $(this).attr('itemid');
        var html = '<div class="list_item">'+
                        '<a href="javascript:void(0)" class="del_item">excluir</a>'+
                        '<input type="text" name="anosem['+itemid+'][]" placeholder="Ano" value="" />'+
                        '<input type="text" class="nota" name="nota['+itemid+'][]" placeholder="Nota" value="" />'+
                        '<label><input type="checkbox" name="status['+itemid+'][]" value="1" /> Aprovado</label>'+ 
                    '</div>';
            
        $('#list'+itemid).append(html);
    });
    
    
    $(document).on('click','.add_op',function(){
        $.post(URLBASE+'/aluno/novaopcaoboletim/',{ id : $('#ALU_ID').val() },function(data) {
            if(data.ok){ $('.cnt-frm-btn').before(data.html); } 
        }, 'json');
    });
    
    $(document).on("click",".del_item",function(){
        $(this).parent().remove();
    });
   
});

